/**
 * 
 */
package soa.security.test.webservice;

import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

/**
 * @author Cre.Gu
 * 
 */
public class HelloWorldClient {
	protected static final org.slf4j.Logger log = org.slf4j.LoggerFactory
			.getLogger(HelloWorldClient.class);

	public final static String WSURL = "http://localhost:8090/services/HelloWorld?wsdl";
	public static final String NAMESPACE = "http://ws.security.soa/";

	public String execute(String text) {
		try {
			String method = "sayHi";
			Service service = new Service();

			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(new URL(WSURL));

			QName qName = new QName(NAMESPACE, method);
			call.setOperationName(qName); // 调用方法

			call.addParameter("text", XMLType.XSD_STRING, ParameterMode.IN);
			call.setReturnType(XMLType.XSD_STRING);

			Object obj = (String) call.invoke(new Object[] { text });
			String retData = (String) obj;
			return retData;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public static void main(String[] args) {
		HelloWorldClient client = new HelloWorldClient();
		System.out.println(client.execute("World"));
	}
}
